package com.briup.srms.sms.service.impl;

import com.briup.srms.sms.bean.Student;
import com.briup.srms.sms.bean.StudentEmployment;
import com.briup.srms.sms.bean.StudentEmploymentExample;
import com.briup.srms.sms.bean.StudentExample;
import com.briup.srms.sms.dao.StudentEmploymentMapper;
import com.briup.srms.sms.dao.StudentMapper;
import com.briup.srms.sms.service.ITestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: sms
 * @description: 测试
 * @author: charles
 * @create: 2022-01-14 12:48
 **/
@Service
public class TestServiceImpl implements ITestService {
    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private StudentEmploymentMapper studentEmploymentMapper;

    @Override
    public void batchUpdateStudentEmployment() {
        StudentExample example = new StudentExample();
        example.createCriteria().andEmploymentIdIsNull();
        List<Student> list = studentMapper.selectByExample(example);
        for(Student s : list){
            StudentEmploymentExample exam = new StudentEmploymentExample();
            exam.createCriteria().andIdCardEqualTo(s.getIdCard());
            List<StudentEmployment> l = studentEmploymentMapper.selectByExample(exam);
            if(l.size()>0){
                s.setEmploymentId(l.get(0).getId());
                studentMapper.updateByPrimaryKey(s);
            }
        }
    }
}
